package com.jeect.web;

import com.jeect.base.domain.User;
import com.jeect.base.util.ResponseBody;
import com.jeect.service.impl.UserService;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

@RestController
@MapperScan(basePackages = "com.jeect.mapper")
public class UserController {

    @Autowired
    private HttpServletRequest request;
    @Autowired
    private UserService userService;
    @Value("${server.port}")
    private String port;

    @GetMapping("/user/{id}")
    public String getUser(@PathVariable String id, HttpServletRequest request){
        System.out.println("Sessionid="+request.getSession().getAttribute("name"));
        return "id="+id+" 端口:"+port;
    }

    @GetMapping("/user/{userid}")
    public Object setsession(@PathVariable String userid){
        HttpSession session = request.getSession();

        session.setAttribute("id",userid);
        System.out.println("sessionid  111111111111111:"+session.getId());
        return "已经设置Session id="+userid;

    }

    @GetMapping("/user/get/")
    public Object getSession(HttpServletRequest request){
        HttpSession session = request.getSession();
        String id = (String)session.getAttribute("id");

        System.out.println("sessionid  222222:"+session.getId());
        return "获取的Session id="+id;
    }
//    @PostMapping("/user/login")
//    public ResponseBody login(User u){
//        User user  = this.userService.getUserByUserName(u.getUserName());
//        return null;
//    }
}
